package org.example.permissionservice.controller;

import org.example.permissionservice.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    /**
     * 绑定用户权限
     * POST /permission/binddefaultrole/{userId}
     */
    @PostMapping("/binddefaultrole/{userId}")
    public void bindDefaultRole(@PathVariable Long userId) {
        permissionService.bindDefaultRole(userId);
    }

    /**
     * 获取用户权限身份
     * GET /permission/getrolecode/{userId}
     */
    @GetMapping("/getrolecode/{userId}")
    public String getRoleCode(@PathVariable Long userId) {
        return permissionService.getUserRoleCode(userId);
    }

    /**
     * 升级为管理员
     * POST /permission/uplevel/{userId}
     */
    @PostMapping("/uplevel/{userId}")
    public void upgradeToAdmin(@PathVariable Long userId) {
        permissionService.upgradeToAdmin(userId);
    }

    /**
     * 降级为普通用户
     * POST /permission/downlevel/{userId}
     */
    @PostMapping("/downlevel/{userId}")
    public void downgradeToUser(@PathVariable Long userId) {
        permissionService.downgradeToUser(userId);
    }

    /**
     * 获取普通用户
     * GET /permission/getnormaluser/
     */
    @GetMapping("/getnormaluser")
    public List<Long> getNormalUser() {
        return permissionService.getNormalUser();
    }
}
